package com.sora.novel.search.manager.feign;

import com.sora.novel.book.dto.resp.BookEsRespDto;
import com.sora.novel.book.feign.BookFeign;
import com.sora.novel.common.constant.ErrorCodeEnum;
import com.sora.novel.common.resp.RestResp;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * @Classname: BookFeignManager
 * @Description: 小说微服务调用 Feign 客户端管理
 * @Author: Stonffe
 * @Date: 2023/6/21 13:44
 */
@Component
@AllArgsConstructor
public class BookFeignManager {
    private final BookFeign bookFeign;

    public List<BookEsRespDto> listEsBooks(Long maxBookId) {
        RestResp<List<BookEsRespDto>> listRestResp = bookFeign.listNextEsBooks(maxBookId);
        if (Objects.equals(ErrorCodeEnum.OK.getCode(), listRestResp.getCode())) {
            return listRestResp.getData();
        }
        return new ArrayList<>(0);
    }
}
